<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page contentType="text/html; charset=utf-8"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>资源库单位修改</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<script src="${pageContext.request.contextPath }/scripts/boot.js" type="text/javascript"></script>
<style type="text/css">
html,body {
	font-size: 12px;
	padding: 0;
	margin: 0;
	border: 0;
	height: 100%;
	overflow: hidden;
}
</style>
</head>
<body>
	<fieldset style="border:solid 1px #aaa;padding:3px;">
	<legend>单位基础信息</legend>
	<form id="form1" method="post">
	<%--
		<input name="aab001" class="mini-hidden" />
	--%>
	<input name="aab001" id="aab001" class="mini-textbox" visible="false" />
	<div style="padding-left:11px;padding-bottom:5px; ">
	<table style="table-layout:fixed;">
	<tr>					
		<td style="width:180px;text-align:right;white-space:nowrap;"><span style="color:red;">*</span>单位名称：</td>
		<td style="width:550px;" colspan="3"><input name="aab004" style="width:97%" id="unit_name" class="mini-textbox"
													required="true" maxlength="25" emptyText="请输入单位名称"
													 /></td>
		<td style="width:180px;text-align:right;white-space:nowrap;"><span style="color:red;">*</span>单位性质：</td>
		<td style="width:180px;"><input id="aab019" name="aab019" class="mini-combobox" style="width:84%;"
										textField="aaa103"
							valueField="aaa102" emptyText="请选择..." showNullItem="true" nullItemText="请选择..."
							url="${pageContext.request.contextPath }/unit.do?method=getselect&lx=AAB019"
							required="true"  />
		</td>
	</tr>
	<tr>
		<td style="width:180px;text-align:right;white-space:nowrap;">统一社会信用代码：</td>
		<td style="width:180px;"><input name="aab998" style="width:84%" id="credit_id" class="mini-textbox"
										 maxlength="18" required="true"
										emptyText="统一社会信用代码(18位)" /></td>
		<td style="width:180px;text-align:right;white-space:nowrap;">组织机构代码：</td>
		<td style="width:180px;"><input name="aab003" style="width:90%" id="organization_id" class="mini-textbox"
									allowInput="false"	maxlength="10"  emptyText="请输入组织机构代码" /></td>
		<td style="width:180px;text-align:right;white-space:nowrap;"><span style="color:red;">*</span>地税登记证号：</td>
		<td style="width:180px;"><input name="aab030" style="width:84%" class="mini-textbox" maxlength="40"
									required="true"	emptyText="请输入地税登记证号"  /></td>
	</tr>
	<tr>
		<td style="width:180px;text-align:right;white-space:nowrap;"><span style="color:red;">*</span>联系人：</td>
		<td style="width:180px;"><input name="aae004" style="width:84%" class="mini-textbox" required="true"
										maxlength="15" emptyText="请输入联系人" /></td>
		<td style="width:180px;text-align:right;white-space:nowrap;"><span style="color:red;">*</span>联系电话：</td>
		<td style="width:180px;"><input name="aae005" style="width:90%" class="mini-textbox" required="true"
										vtype="int" maxlength="11" emptyText="请输入联系电话" /></td>
		<td style="width:180px;text-align:right;white-space:nowrap;"><span style="color:red;">*</span>法定代表人姓名：</td>
		<td style="width:180px;"><input name="aab013" style="width:84%" class="mini-textbox" required="true"
										maxlength="15" emptyText="请输入法定代表人姓名" /></td>
	</tr>
	<tr>
		<td style="width:180px;text-align:right;white-space:nowrap;"><span style="color:red;">*</span>法定代表人证件类型：</td>
		<td style="width:180px;"><input name="aae018" class="mini-combobox" valueField="aaa102" textField="aaa103"
										style="width:84%" id="documenttype" 
										url="${pageContext.request.contextPath }/unit.do?method=getselect&lx=AAC058"
										required="true" emptyText="请选择..." showNullItem="true"
										nullItemText="请选择..." /></td>
		<td style="width:180px;text-align:right;white-space:nowrap;"><span style="color:red;">*</span>法定代表人证件号码：</td>
		<td style="width:180px;"><input name="aab014" style="width:90%" class="mini-textbox" maxlength="18"
										required="true"  emptyText="请输入法定代表人证件号码" /></td>
		<td style="width:180px;text-align:right;white-space:nowrap;"><span style="color:red;">*</span>法定代表人联系电话：</td>
		<td style="width:180px;"><input name="aab015" style="width:84%" class="mini-textbox" vtype="int" maxlength="11"
										required="true" emptyText="请输入法定代表人联系电话" /></td>
	</tr>	
	<tr>
		<td style="width:180px;text-align:right;white-space:nowrap;"><span style="color:red;">*</span>邮政编码：</td>
		<td style="width:180px;"><input name="aae007" style="width:84%" class="mini-textbox" 
									required="true"	vtype="int" maxlength="6" emptyText="请输入邮政编码" /></td>
		<td style="width:180px;text-align:right;white-space:nowrap;"><span style="color:red;">*</span>变更原因：</td>
		<td colspan="3" ><input name="aae160" style="width:95%" class="mini-textbox" required="true" allowInput="true"/></td>
	</tr>								
	</table>
	</div>
		<div style="text-align:center;padding:10px;">
			<a class="mini-button" onclick="saveData1" iconCls="icon-ok" style="width:60px;margin-right:20px;">确定</a> 
			<a class="mini-button" iconCls="icon-close" onclick="onCancel" style="width:60px;">取消</a>
		</div>
	</form>
	</fieldset>
<script type="text/javascript">
	mini.parse();
	var form = new mini.Form("form1");
	function ondwChanged(){
	    var credit_id = mini.get("#credit_id");
   	 	var organization_id = mini.get("#organization_id");
    	var landtax = mini.getbyName("aab030");
		var f=mini.get("#aab019").getValue();
		if(f=="10"){
			landtax.setValue("");			    	    
		    credit_id.setEmptyText("统一社会信用代码(18位)");
		    credit_id.setAllowInput(true);
		    credit_id.setRequired(false);
			organization_id.setAllowInput(true);
			landtax.setAllowInput(true);
			landtax.setEmptyText("请输入地税登记证号");				
		}
		//机关、事业单位
		if(f=="30"||f=="50"){
		     landtax.setValue("");
		    credit_id.setValue("");
		    credit_id.setEmptyText("");
			credit_id.setAllowInput(false);		    
			organization_id.setAllowInput(true);
			organization_id.setRequired(true);
			landtax.setAllowInput(false);
			landtax.setEmptyText("");
		}
		//社会团体
		if(f=="70"){
		    credit_id.setValue("");	
		    credit_id.setEmptyText("");
	        credit_id.setAllowInput(false);
			organization_id.setAllowInput(true);
			organization_id.setRequired(true);
			landtax.setAllowInput(true);
			landtax.setEmptyText("请输入地税登记证号");
		}
		if(f=="81") {
			credit_id.setValue("");	
			landtax.setValue("");
			credit_id.setEmptyText("统一社会信用代码(18位)");
			credit_id.setAllowInput(true);
			credit_id.setRequired(false);
			organization_id.setAllowInput(true);
			organization_id.setRequired(false);
			landtax.setAllowInput(true);
			landtax.setEmptyText("请输入地税登记证号");
		}
	}
    var judge=true;
    var judge2=true;
    mini.parse();
    var aab131 = mini.getbyName("aab998").getValue();
    var aab003 = mini.getbyName("aab003").getValue();
    if(aab131==" "){mini.getbyName("aab998").setValue("");}
    if(aab003==" "){mini.getbyName("aab003").setValue("");}
    function SaveData() {
    	var o = form.getData();            
        form.validate();
        if (form.isValid() == false) return;
        if(form.isValid()==true){
	      	   mini.mask({el: document.body,cls: 'mini-mask-loading',html: '保存中...'});
	      	 }
        var json = mini.encode([o]);           
        $.ajax({
        	url: "/zyk/unit.do?method=saveunit",
			type: 'post',
            data: { data: json},
            cache: false,
            success: function (text) {
            	mini.unmask();
            	if(text == "0")
            	{
            		CloseWindow("save");
            		//mini.alert("单位变更成功!");
					
            	}else
            	{
            		
            		if(text.length > 5)
    				{
    					var ssss = text.substring(0,4);
    					if(ssss == "hint")
    					{
    						var tttt = text.substring(5,text.length);
    						if(confirm(tttt)==true)
    						{
    							saveDatas();
    							return;
    						}
    						else 
    						{
    							//form.clear();
    							//CloseWindow("save");
    							return ;
    						}
    					}
    				}
            		mini.alert(text);
            	}
            	
            	
            },
            error: function (jqXHR, textStatus, errorThrown) {
            	mini.alert(jqXHR.responseText);
                CloseWindow();
            }
        });
    }
    function loading() {
        mini.mask({
            el: document.body,
            cls: 'mini-mask-loading',
            html: '加载中...'
        });
        setTimeout(function () {
            mini.unmask(document.body);
        }, 3000);
    }
        ////////////////////
    //标准方法接口定义
    function SetData(data) {
    	if (data.action == "edit") {
 	 //跨页面传递的数据对象，克隆后才可以安全使用              
        	data = mini.clone(data);                        
        	$.ajax({               
            	url: "/zyk/unit.do?method=getunitdata",
                cache: false,
                data:{id:data.id},
                success: function (text) {                 
                	var o = mini.decode(text);                      
                    form.setData(o);
                    form.setChanged(false);
                }
            });
        }
    }
    function GetData() {
        var o = form.getData();
        return o;
    }
    function CloseWindow(action) {            
        if (action == "close" && form.isChanged()) {
            if (confirm("数据被修改了，是否先保存？")) {
                return false;
            }
        }
        if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
        	else window.close();            
        }
    function onOk(e) {      
        var credit_id = mini.get("#credit_id").getValue();
	 	var organization_id = mini.get("#organization_id").getValue();
   	 	var f=mini.get("#aab019").getValue();
   	 	if(f=='10'&&credit_id==''&&organization_id==''){
   	 		mini.alert("统一社会信用代码、组织机构代码不能同时为空");
   	 		judge2=false;
   	 	}
   	 	if(f=='10'&&credit_id!=''&&organization_id!=''){
			mini.alert("统一社会信用代码、组织机构代码不能同时采集");
			judge2=false;
	   	 }	   	 	   	 	
        checkName();       
        onNumber(e);
        var aab998 = mini.getbyName("aab998").getValue();	 
        if(aab998.length>0){
        	CheckNumber(e);
        }        
        if(judge&judge2){
        	SaveData();
        }
        
       }
        function onCancel(e) {
            CloseWindow("cancel");
        }
        
        function onNumber(e) {
    		var zjlx = mini.get("#documenttype").getValue();
    		var aab014 = mini.getbyName("aab014").getValue().trim();
    		if (zjlx == '01') {
    			$.ajax({
    				url : "/zyk/unit.do?method=checksfz&id=" + aab014,
    				success : function(res) {
    				if ("0" != res) {
    					mini.alert(res);
    					mini.getbyName("aab014").setValue("");
    				}
    				}
    			});
    		}
    	}
	function isNumber(v){
        var tel = /^\d{6}(18|19|20)?\d{2}(0[1-9]|1[12])(0[1-9]|[12]\d|3[01])\d{3}(\d|X)$/i;
        var flag = true;
        if(!tel.test(v)){
            flag = false;
        }else{
            var arrInt = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
            var arrCh = new Array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2');
            var nTemp = 0, i;
            var temp = v.substring(0,17);
            for (i = 0; i < temp.length; i++) {
                 nTemp += temp.substr(i, 1) * arrInt[i];
                }
                temp += arrCh[nTemp % 11];
            if(temp != v) {
               flag = false;
            }
        }
       
          return flag;
    }
    function isOrganization(v){
        var re = new RegExp("^([0-9A-Z]){8}-[0-9|X]$");
        if (re.test(v)) return true;
        return false;
    }
	//检测组织ID是否重复
    function CheckOrganizationId(v){
        if(v.isValid){
			if(isOrganization(v.value) == false&&v.value!=''){
				v.errorText = "组织机构输入不合法";
				v.isValid = false;
			}
		 }
		var id = mini.get("#organization_id").getValue().trim();
        var aab001=mini.get("#aab001").getValue().trim();          
	 	$.ajax({
        	url: "/zyk/unit.do?method=getunitorganizationid",
            dataType : 'JSON',
			data : {id:id,aab001:aab001},
            success: function(result) {
			//已经存在组织机构代码字提示用户
				if(result != null){
					mini.get("#organization_id").setValue();  
						mini.alert("组织机构代码重复，请重新输入");
						judge=false;
				}else{
					judge=true;
				}
			}	
    	});
    }
	//发ajax请求到后台判断用户名是否重复
    function checkName(){
    	var name = mini.get("#unit_name").getValue();          
    	var id = mini.get("#aab001").getValue();     
		$.ajax({
        	url: "/zyk/unit.do?method=getunitname",
            async:false,
            dataType : 'JSON',
			data : {name:name},
            success: function(result) {
		//已经存在该名字提示用户
				if(result != null){
					if(id==result.aab001){judge=true;}
					else{
						mini.alert("该单位已注册，请核实");
						judge=false;
					}
				}else{
					judge=true;
				}
			}	
         });
    }
    function CheckNumber(e){
		var AAB998 = mini.getbyName("aab998").getValue();
		if(AAB998.length<18&AAB998.length>=1){
			mini.alert("信用编码必须为18位");
	 	// e.errorText = "信用编码必须为18位"; 
		 // e.isValid = false;
			judge=false;
		} else {
		 judge=true;
		}
    }
	function onDrawDate(e) {
		var date = e.date;
		var d = new Date();
		if (date.getTime() >= d.getTime()) {
		    e.allowSelect = false;
		}
	}
	
	function saveData1()
	{
		SaveData();
	}
	
	function saveDatas()
	{
		var o = form.getData();			
		form.validate();
		if (form.isValid() == false)
		return;
		var json = mini.encode([o]);
		$.ajax({
			url : "/zyk/unit.do?method=update",
			type : 'post',
			data : {
				data : json
			},
			cache : false,
			success : function(text) {
				mini.unmask();
				if(text == "0")
				{
					form.clear();
					CloseWindow("save");
				}
				else
				{
					
					mini.alert(text);
				}
				
				
				
			},
			error : function(jqXHR, textStatus, errorThrown) {
				mini.alert(jqXHR.responseText);
				CloseWindow();
			}
		});
	}
	
    </script>
</body>
</html>
